#pragma once
class MyCircularQueue {

private:
    int* data;    // 存储元素的数组
    int front;    // 队头指针
    int rear;     // 队尾指针（下一个插入位置）
    int size;     // 当前元素数量
    int capacity; // 队列容量

public:
    MyCircularQueue(int k) {
        data = new int[k];
        capacity = k;
        size = 0;
        rear = 0;
        front = 0;
    }

    // 释放动态分配的数组内存
    ~MyCircularQueue() {
        delete[] data;
    }

    bool enQueue(int value) {
        if (isFull()) return false;
        data[rear] = value;
        rear = (rear + 1) % capacity; // 循环后移
        size++;
        return true;
    }

    bool deQueue() {
        if (isEmpty()) return false;
        front = (front + 1) % capacity;
        size--;
        return true;
    }

    int Front() {
        if (isEmpty()) return -1;
        return data[front];
    }

    int Rear() {
        if (isEmpty()) return -1;
        int location = (rear - 1 + capacity) % capacity;
        return data[location];
    }

    bool isEmpty() {
        return size == 0;
    }

    bool isFull() {
        return size == capacity;
    }
};

/**
 * Your MyCircularQueue object will be instantiated and called as such:
 * MyCircularQueue* obj = new MyCircularQueue(k);
 * bool param_1 = obj->enQueue(value);
 * bool param_2 = obj->deQueue();
 * int param_3 = obj->Front();
 * int param_4 = obj->Rear();
 * bool param_5 = obj->isEmpty();
 * bool param_6 = obj->isFull();
 */
